package com.ruoyi.reportsnhnt.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.core.domain.PageQuery;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import com.ruoyi.reportsnhnt.domain.bo.ReportSnhntPhbsjBaDetailBo;
import com.ruoyi.reportsnhnt.domain.vo.ReportSnhntPhbsjBaDetailVo;
import com.ruoyi.reportsnhnt.domain.ReportSnhntPhbsjBaDetail;
import com.ruoyi.reportsnhnt.mapper.ReportSnhntPhbsjBaDetailMapper;
import com.ruoyi.reportsnhnt.service.IReportSnhntPhbsjBaDetailService;

import java.util.List;
import java.util.Map;
import java.util.Collection;

/**
 * 普通混凝土配合比设计试验检测记录详情Service业务层处理
 *
 * @author zxs
 * @date 2024-06-21
 */
@RequiredArgsConstructor
@Service
public class ReportSnhntPhbsjBaDetailServiceImpl implements IReportSnhntPhbsjBaDetailService {

    private final ReportSnhntPhbsjBaDetailMapper baseMapper;

    /**
     * 查询普通混凝土配合比设计试验检测记录详情
     */
    @Override
    public ReportSnhntPhbsjBaDetailVo queryById(Long id){
        return baseMapper.selectVoById(id);
    }

    /**
     * 查询普通混凝土配合比设计试验检测记录详情列表
     */
    @Override
    public TableDataInfo<ReportSnhntPhbsjBaDetailVo> queryPageList(ReportSnhntPhbsjBaDetailBo bo, PageQuery pageQuery) {
        LambdaQueryWrapper<ReportSnhntPhbsjBaDetail> lqw = buildQueryWrapper(bo);
        Page<ReportSnhntPhbsjBaDetailVo> result = baseMapper.selectVoPage(pageQuery.build(), lqw);
        return TableDataInfo.build(result);
    }

    /**
     * 查询普通混凝土配合比设计试验检测记录详情列表
     */
    @Override
    public List<ReportSnhntPhbsjBaDetailVo> queryList(ReportSnhntPhbsjBaDetailBo bo) {
        LambdaQueryWrapper<ReportSnhntPhbsjBaDetail> lqw = buildQueryWrapper(bo);
        return baseMapper.selectVoList(lqw);
    }

    private LambdaQueryWrapper<ReportSnhntPhbsjBaDetail> buildQueryWrapper(ReportSnhntPhbsjBaDetailBo bo) {
        Map<String, Object> params = bo.getParams();
        LambdaQueryWrapper<ReportSnhntPhbsjBaDetail> lqw = Wrappers.lambdaQuery();
        lqw.eq(bo.getExcelId() != null, ReportSnhntPhbsjBaDetail::getExcelId, bo.getExcelId());
        lqw.eq(bo.getBianh() != null, ReportSnhntPhbsjBaDetail::getBianh, bo.getBianh());
        lqw.eq(StringUtils.isNotBlank(bo.getShejqddj()), ReportSnhntPhbsjBaDetail::getShejqddj, bo.getShejqddj());
        lqw.eq(StringUtils.isNotBlank(bo.getQuybw()), ReportSnhntPhbsjBaDetail::getQuybw, bo.getQuybw());
        lqw.eq(bo.getKangyrq() != null, ReportSnhntPhbsjBaDetail::getKangyrq, bo.getKangyrq());
        lqw.eq(StringUtils.isNotBlank(bo.getLingq()), ReportSnhntPhbsjBaDetail::getLingq, bo.getLingq());
        lqw.eq(bo.getQhzq1() != null, ReportSnhntPhbsjBaDetail::getQhzq1, bo.getQhzq1());
        lqw.eq(bo.getQqdq1() != null, ReportSnhntPhbsjBaDetail::getQqdq1, bo.getQqdq1());
        lqw.eq(bo.getQpjqdq1() != null, ReportSnhntPhbsjBaDetail::getQpjqdq1, bo.getQpjqdq1());
        lqw.eq(bo.getQhzq2() != null, ReportSnhntPhbsjBaDetail::getQhzq2, bo.getQhzq2());
        lqw.eq(bo.getQqdq2() != null, ReportSnhntPhbsjBaDetail::getQqdq2, bo.getQqdq2());
        lqw.eq(bo.getQpjqdq2() != null, ReportSnhntPhbsjBaDetail::getQpjqdq2, bo.getQpjqdq2());
        lqw.eq(bo.getQhzq3() != null, ReportSnhntPhbsjBaDetail::getQhzq3, bo.getQhzq3());
        lqw.eq(bo.getQqdq3() != null, ReportSnhntPhbsjBaDetail::getQqdq3, bo.getQqdq3());
        lqw.eq(bo.getQpjqdq3() != null, ReportSnhntPhbsjBaDetail::getQpjqdq3, bo.getQpjqdq3());
        lqw.eq(bo.getEhzq1() != null, ReportSnhntPhbsjBaDetail::getEhzq1, bo.getEhzq1());
        lqw.eq(bo.getEqdq1() != null, ReportSnhntPhbsjBaDetail::getEqdq1, bo.getEqdq1());
        lqw.eq(bo.getEpjqdq1() != null, ReportSnhntPhbsjBaDetail::getEpjqdq1, bo.getEpjqdq1());
        lqw.eq(bo.getEhzq2() != null, ReportSnhntPhbsjBaDetail::getEhzq2, bo.getEhzq2());
        lqw.eq(bo.getEqdq2() != null, ReportSnhntPhbsjBaDetail::getEqdq2, bo.getEqdq2());
        lqw.eq(bo.getEpjqdq2() != null, ReportSnhntPhbsjBaDetail::getEpjqdq2, bo.getEpjqdq2());
        lqw.eq(bo.getEhzq3() != null, ReportSnhntPhbsjBaDetail::getEhzq3, bo.getEhzq3());
        lqw.eq(bo.getEqdq3() != null, ReportSnhntPhbsjBaDetail::getEqdq3, bo.getEqdq3());
        lqw.eq(bo.getEpjqdq3() != null, ReportSnhntPhbsjBaDetail::getEpjqdq3, bo.getEpjqdq3());
        lqw.eq(bo.getShiyrq7q() != null, ReportSnhntPhbsjBaDetail::getShiyrq7q, bo.getShiyrq7q());
        lqw.eq(bo.getShiyrq28q() != null, ReportSnhntPhbsjBaDetail::getShiyrq28q, bo.getShiyrq28q());
        lqw.eq(bo.getShiyrq3() != null, ReportSnhntPhbsjBaDetail::getShiyrq3, bo.getShiyrq3());
        lqw.eq(bo.getShiyrq7() != null, ReportSnhntPhbsjBaDetail::getShiyrq7, bo.getShiyrq7());
        lqw.eq(bo.getShiyrq28() != null, ReportSnhntPhbsjBaDetail::getShiyrq28, bo.getShiyrq28());
        lqw.eq(StringUtils.isNotBlank(bo.getChengymj()), ReportSnhntPhbsjBaDetail::getChengymj, bo.getChengymj());
        lqw.eq(bo.getHuansxs() != null, ReportSnhntPhbsjBaDetail::getHuansxs, bo.getHuansxs());
        lqw.eq(StringUtils.isNotBlank(bo.getShuijb()), ReportSnhntPhbsjBaDetail::getShuijb, bo.getShuijb());
        lqw.eq(StringUtils.isNotBlank(bo.getShal()), ReportSnhntPhbsjBaDetail::getShal, bo.getShal());
        lqw.eq(StringUtils.isNotBlank(bo.getShuin()), ReportSnhntPhbsjBaDetail::getShuin, bo.getShuin());
        lqw.eq(StringUtils.isNotBlank(bo.getXijl()), ReportSnhntPhbsjBaDetail::getXijl, bo.getXijl());
        lqw.eq(StringUtils.isNotBlank(bo.getCujl()), ReportSnhntPhbsjBaDetail::getCujl, bo.getCujl());
        lqw.eq(StringUtils.isNotBlank(bo.getShui()), ReportSnhntPhbsjBaDetail::getShui, bo.getShui());
        lqw.eq(StringUtils.isNotBlank(bo.getJuqsxgxnjsj()), ReportSnhntPhbsjBaDetail::getJuqsxgxnjsj, bo.getJuqsxgxnjsj());
        lqw.eq(StringUtils.isNotBlank(bo.getLilrz()), ReportSnhntPhbsjBaDetail::getLilrz, bo.getLilrz());
        lqw.eq(StringUtils.isNotBlank(bo.getZhonglphb()), ReportSnhntPhbsjBaDetail::getZhonglphb, bo.getZhonglphb());
        lqw.eq(StringUtils.isNotBlank(bo.getShuinl()), ReportSnhntPhbsjBaDetail::getShuinl, bo.getShuinl());
        lqw.eq(StringUtils.isNotBlank(bo.getXijll()), ReportSnhntPhbsjBaDetail::getXijll, bo.getXijll());
        lqw.eq(StringUtils.isNotBlank(bo.getCujll()), ReportSnhntPhbsjBaDetail::getCujll, bo.getCujll());
        lqw.eq(StringUtils.isNotBlank(bo.getShuil()), ReportSnhntPhbsjBaDetail::getShuil, bo.getShuil());
        lqw.eq(StringUtils.isNotBlank(bo.getJuqsxgxnjsjl()), ReportSnhntPhbsjBaDetail::getJuqsxgxnjsjl, bo.getJuqsxgxnjsjl());
        lqw.eq(StringUtils.isNotBlank(bo.getShicrz()), ReportSnhntPhbsjBaDetail::getShicrz, bo.getShicrz());
        lqw.eq(StringUtils.isNotBlank(bo.getShictld()), ReportSnhntPhbsjBaDetail::getShictld, bo.getShictld());
        lqw.eq(bo.getChengxrq() != null, ReportSnhntPhbsjBaDetail::getChengxrq, bo.getChengxrq());
        lqw.eq(StringUtils.isNotBlank(bo.getShijcc()), ReportSnhntPhbsjBaDetail::getShijcc, bo.getShijcc());
        lqw.eq(bo.getShz1() != null, ReportSnhntPhbsjBaDetail::getShz1, bo.getShz1());
        lqw.eq(bo.getSqd1() != null, ReportSnhntPhbsjBaDetail::getSqd1, bo.getSqd1());
        lqw.eq(bo.getSpjqd1() != null, ReportSnhntPhbsjBaDetail::getSpjqd1, bo.getSpjqd1());
        lqw.eq(bo.getShz2() != null, ReportSnhntPhbsjBaDetail::getShz2, bo.getShz2());
        lqw.eq(bo.getSqd2() != null, ReportSnhntPhbsjBaDetail::getSqd2, bo.getSqd2());
        lqw.eq(bo.getSpjqd2() != null, ReportSnhntPhbsjBaDetail::getSpjqd2, bo.getSpjqd2());
        lqw.eq(bo.getShz3() != null, ReportSnhntPhbsjBaDetail::getShz3, bo.getShz3());
        lqw.eq(bo.getSqd3() != null, ReportSnhntPhbsjBaDetail::getSqd3, bo.getSqd3());
        lqw.eq(bo.getSpjqd3() != null, ReportSnhntPhbsjBaDetail::getSpjqd3, bo.getSpjqd3());
        lqw.eq(bo.getQhz1() != null, ReportSnhntPhbsjBaDetail::getQhz1, bo.getQhz1());
        lqw.eq(bo.getQqd1() != null, ReportSnhntPhbsjBaDetail::getQqd1, bo.getQqd1());
        lqw.eq(bo.getQpjqd1() != null, ReportSnhntPhbsjBaDetail::getQpjqd1, bo.getQpjqd1());
        lqw.eq(bo.getQhz2() != null, ReportSnhntPhbsjBaDetail::getQhz2, bo.getQhz2());
        lqw.eq(bo.getQqd2() != null, ReportSnhntPhbsjBaDetail::getQqd2, bo.getQqd2());
        lqw.eq(bo.getQpjqd2() != null, ReportSnhntPhbsjBaDetail::getQpjqd2, bo.getQpjqd2());
        lqw.eq(bo.getQhz3() != null, ReportSnhntPhbsjBaDetail::getQhz3, bo.getQhz3());
        lqw.eq(bo.getQqd3() != null, ReportSnhntPhbsjBaDetail::getQqd3, bo.getQqd3());
        lqw.eq(bo.getQpjqd3() != null, ReportSnhntPhbsjBaDetail::getQpjqd3, bo.getQpjqd3());
        lqw.eq(bo.getEhz1() != null, ReportSnhntPhbsjBaDetail::getEhz1, bo.getEhz1());
        lqw.eq(bo.getEqd1() != null, ReportSnhntPhbsjBaDetail::getEqd1, bo.getEqd1());
        lqw.eq(bo.getEpjqd1() != null, ReportSnhntPhbsjBaDetail::getEpjqd1, bo.getEpjqd1());
        lqw.eq(bo.getEhz2() != null, ReportSnhntPhbsjBaDetail::getEhz2, bo.getEhz2());
        lqw.eq(bo.getEqd2() != null, ReportSnhntPhbsjBaDetail::getEqd2, bo.getEqd2());
        lqw.eq(bo.getEpjqd2() != null, ReportSnhntPhbsjBaDetail::getEpjqd2, bo.getEpjqd2());
        lqw.eq(bo.getEhz3() != null, ReportSnhntPhbsjBaDetail::getEhz3, bo.getEhz3());
        lqw.eq(bo.getEqd3() != null, ReportSnhntPhbsjBaDetail::getEqd3, bo.getEqd3());
        lqw.eq(bo.getEpjqd3() != null, ReportSnhntPhbsjBaDetail::getEpjqd3, bo.getEpjqd3());
        return lqw;
    }

    /**
     * 新增普通混凝土配合比设计试验检测记录详情
     */
    @Override
    public Boolean insertByBo(ReportSnhntPhbsjBaDetailBo bo) {
        ReportSnhntPhbsjBaDetail add = BeanUtil.toBean(bo, ReportSnhntPhbsjBaDetail.class);
        validEntityBeforeSave(add);
        boolean flag = baseMapper.insert(add) > 0;
        if (flag) {
            bo.setId(add.getId());
        }
        return flag;
    }

    /**
     * 修改普通混凝土配合比设计试验检测记录详情
     */
    @Override
    public Boolean updateByBo(ReportSnhntPhbsjBaDetailBo bo) {
        ReportSnhntPhbsjBaDetail update = BeanUtil.toBean(bo, ReportSnhntPhbsjBaDetail.class);
        validEntityBeforeSave(update);
        return baseMapper.updateById(update) > 0;
    }

    /**
     * 保存前的数据校验
     */
    private void validEntityBeforeSave(ReportSnhntPhbsjBaDetail entity){
        //TODO 做一些数据校验,如唯一约束
    }

    /**
     * 批量删除普通混凝土配合比设计试验检测记录详情
     */
    @Override
    public Boolean deleteWithValidByIds(Collection<Long> ids, Boolean isValid) {
        if(isValid){
            //TODO 做一些业务上的校验,判断是否需要校验
        }
        return baseMapper.deleteBatchIds(ids) > 0;
    }
}
